package com.betterjr.modules.application.entity;

import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

import com.betterjr.common.annotation.MetaData;
import com.betterjr.common.entity.BetterjrEntity;

@Access(AccessType.FIELD)
@Entity
@Table(name = "t_ams_resources")
public class AmsResource implements BetterjrEntity {

    /** 
     * @Fields serialVersionUID : 
     */
    private static final long serialVersionUID = 1285487382778294961L;

    @Id
    @Column(name = "ID", columnDefinition = "INTEGER")
    @MetaData(value = "流水号", comments = "流水号")
    private Long id;

    /**
     * 名称
     */
    @Column(name = "c_application_name", columnDefinition = "VARCHAR")
    @MetaData(value = "名称", comments = "名称")
    private String applicationName;

    /**
     * 编码
     */
    @Column(name = "c_code", columnDefinition = "VARCHAR")
    @MetaData(value = "编码", comments = "编码")
    private String code;

    /**
     * 状态  1 生效  9 不生效
     */
    @Column(name = "c_businStatus", columnDefinition = "VARCHAR")
    @MetaData(value = "状态  1 生效  9 不生效", comments = "状态  1 生效  9 不生效")
    private String businStatus;

    /**
     * 模块名称
     */
    @Column(name = "c_model_name", columnDefinition = "VARCHAR")
    @MetaData(value = "模块名称", comments = "模块名称")
    private String modelName;

    /**
     * 资源名称
     */
    @Column(name = "c_resource_name", columnDefinition = "VARCHAR")
    @MetaData(value = "资源名称", comments = "资源名称")
    private String resourceName;

    /**
     * 访问地址
     */
    @Column(name = "c_url", columnDefinition = "VARCHAR")
    @MetaData(value = "访问地址", comments = "访问地址")
    private String url;

    /**
     * 组名称
     */
    @Column(name = "c_applicationgroup_name", columnDefinition = "VARCHAR")
    @MetaData(value = "组名称", comments = "组名称")
    private String applicationGroupName;

    /**
     * 组id
     */
    @Column(name = "l_applicationgroup_id", columnDefinition = "VARCHAR")
    @MetaData(value = "组id", comments = "组id")
    private String applicationGroupId;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getBusinStatus() {
        return businStatus;
    }

    public void setBusinStatus(String businStatus) {
        this.businStatus = businStatus;
    }

    public String getApplicationName() {
        return applicationName;
    }

    public void setApplicationName(String applicationName) {
        this.applicationName = applicationName;
    }

    public String getModelName() {
        return modelName;
    }

    public void setModelName(String modelName) {
        this.modelName = modelName;
    }

    public String getResourceName() {
        return resourceName;
    }

    public void setResourceName(String resourceName) {
        this.resourceName = resourceName;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getApplicationGroupName() {
        return applicationGroupName;
    }

    public void setApplicationGroupName(String applicationGroupName) {
        this.applicationGroupName = applicationGroupName;
    }

    public String getApplicationGroupId() {
        return applicationGroupId;
    }

    public void setApplicationGroupId(String applicationGroupId) {
        this.applicationGroupId = applicationGroupId;
    }

    @Override
    public String toString() {
        return "AmsResource [id=" + id + ", applicationName=" + applicationName + ", code=" + code + ", businStatus="
                + businStatus + ", modelName=" + modelName + ", resourceName=" + resourceName + ", url=" + url
                + ", applicationGroupName=" + applicationGroupName + ", applicationGroupId=" + applicationGroupId + "]";
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((applicationGroupId == null) ? 0 : applicationGroupId.hashCode());
        result = prime * result + ((applicationGroupName == null) ? 0 : applicationGroupName.hashCode());
        result = prime * result + ((applicationName == null) ? 0 : applicationName.hashCode());
        result = prime * result + ((businStatus == null) ? 0 : businStatus.hashCode());
        result = prime * result + ((code == null) ? 0 : code.hashCode());
        result = prime * result + ((id == null) ? 0 : id.hashCode());
        result = prime * result + ((modelName == null) ? 0 : modelName.hashCode());
        result = prime * result + ((resourceName == null) ? 0 : resourceName.hashCode());
        result = prime * result + ((url == null) ? 0 : url.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (!(obj instanceof AmsResource)) {
            return false;
        }
        AmsResource other = (AmsResource) obj;
        if (applicationGroupId == null) {
            if (other.applicationGroupId != null) {
                return false;
            }
        } else if (!applicationGroupId.equals(other.applicationGroupId)) {
            return false;
        }
        if (applicationGroupName == null) {
            if (other.applicationGroupName != null) {
                return false;
            }
        } else if (!applicationGroupName.equals(other.applicationGroupName)) {
            return false;
        }
        if (applicationName == null) {
            if (other.applicationName != null) {
                return false;
            }
        } else if (!applicationName.equals(other.applicationName)) {
            return false;
        }
        if (businStatus == null) {
            if (other.businStatus != null) {
                return false;
            }
        } else if (!businStatus.equals(other.businStatus)) {
            return false;
        }
        if (code == null) {
            if (other.code != null) {
                return false;
            }
        } else if (!code.equals(other.code)) {
            return false;
        }
        if (id == null) {
            if (other.id != null) {
                return false;
            }
        } else if (!id.equals(other.id)) {
            return false;
        }
        if (modelName == null) {
            if (other.modelName != null) {
                return false;
            }
        } else if (!modelName.equals(other.modelName)) {
            return false;
        }
        if (resourceName == null) {
            if (other.resourceName != null) {
                return false;
            }
        } else if (!resourceName.equals(other.resourceName)) {
            return false;
        }
        if (url == null) {
            if (other.url != null) {
                return false;
            }
        } else if (!url.equals(other.url)) {
            return false;
        }
        return true;
    }

    public AmsResourceExtend conventToExtend() {

        AmsResourceExtend extend = new AmsResourceExtend();

        extend.setId(this.getId());
        extend.setResourceCode(this.getCode());
        extend.setResourceName(
                "[" + this.getApplicationName() + "][" + this.getModelName() + "]" + this.getResourceName());
        extend.setUrl(this.getUrl());

        return extend;
    }

}
